home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13638 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  56 lines

  1. Path: nntp-hub.barrnet.net!biosys!apldbio.com
  2. From: nasser@apldbio.com (Nasser Abbasi)
  3. Newsgroups: comp.lang.c++
  4. Subject: exit() and flushing data to ofstream files?
  5. Message-ID: <31584F18.29B2@apldbio.com>
  6. Date: 26 Mar 96 20:10:00 GMT
  7. Sender: news@biosys.apldbio.COM
  8. Organization: Applied BioSystems
  9. X-Mailer: Mozilla 2.01 (X11; I; SunOS 5.5 sun4m)
  10. MIME-Version: 1.0
  11. CC: nasser@apldbio.com
  12. Content-Type: text/plain; charset=us-ascii
  13. Content-Transfer-Encoding: 7bit
  14.  
  15. hi,
  16.  
  17. I am confused about something.
  18.  
  19. according to "the C++ programming language", Bjarne Stroustrup
  20. page 85 it says:
  21. "..This can be done by calling exit(), which first clean things
  22. like output streams."
  23.  
  24. I take this as meaning that calling exit() from your C++
  25. program will cause buffers to be flushed out to ofstream
  26. files . well, this does no seem to be the case, this little 
  27. program shows that exit() do not flush data to file. 
  28.  
  29. #include <fstream.h>
  30. #include <stdlib.h>
  31.  
  32. main()
  33. {
  34. ofstream  f;
  35.  
  36.  f.open("tmp1");
  37.  f.put('X');
  38.  //f.flush();
  39.   exit(1);       // this does not flush data to file
  40.  return 1;
  41.  
  42. }
  43.  
  44. Now looking at tmp I see no data in it.
  45.  
  46. This is on Sun Solaris 2.5, using CC compiler.
  47.  
  48. What is the recommended way to terminate the program
  49. and have all buffers flushed automatically without having
  50. to explicity call flush() on each open stream file ? 
  51. Is this a bug or a feature of exit() ?
  52.  
  53. thanks,
  54. Nasser
  55. Applied BioSystems
  56.